package com.czkj.hwz.decorate.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.czkj.hwz.decorate.base.HttpUrl;
import com.czkj.hwz.decorate.bean.Goods;
import com.czkj.hwz.decorate.R;

import org.xutils.x;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/10/7.
 */

public class GoodsAdapter extends BaseAdapter {
    private Context mContext;
    private ArrayList<Goods> mList;

    public GoodsAdapter(Context context) {
        mContext = context;
    }

    public GoodsAdapter(Context context, ArrayList<Goods> list) {
        mContext = context;
        mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Goods getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view==null){
            viewHolder=new ViewHolder();
            view = LayoutInflater.from(mContext).inflate(R.layout.grideview_goods_item,null);
            viewHolder.img= (ImageView) view.findViewById(R.id.img);
            viewHolder.tv_title= (TextView) view.findViewById(R.id.tv_title);
            view.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) view.getTag();
        }
        viewHolder.tv_title.setText(mList.get(i).getName());
        x.image().bind(viewHolder.img, HttpUrl.BASE_URL+mList.get(i).getSmallImg());
        return view;
    }
    static class ViewHolder{
        ImageView img;
        TextView tv_title;
    }
}
